package com.lxmes.business.service.Impl;


import com.lxmes.business.domain.*;
import com.lxmes.business.mapper.CcRukuInfoMapper;
import com.lxmes.business.service.ICcRukuInfoWebServiceService;
import com.lxmes.common.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;


@Component
@Service
public class ICcRukuInfoWebServiceServiceImpl implements ICcRukuInfoWebServiceService {

    private final WLogin wLogin;

    @Autowired
    public ICcRukuInfoWebServiceServiceImpl(WLogin wLogin) {
        this.wLogin = wLogin;
    }

    @Autowired
    private CcRukuInfoMapper ccRukuInfoMapper;

    @Override
    public Map<String, String> zhixingURuku(Long[] ids) {

        //根据ids查询
        List<CcRukuInfo> list = ccRukuInfoMapper.selectZxCcRukuUInfo(ids);
        //生成表头信息
        PuStoreInDomHead puStoreInDomHead = new PuStoreInDomHead();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        puStoreInDomHead.setDdate(sdf.format(new Date()));
        puStoreInDomHead.setCvenabbname("济南森峰激光科技股份有限公司");
        puStoreInDomHead.setIverifystate("0");
        puStoreInDomHead.setIswfcontrolled("0");
        puStoreInDomHead.setCmaker(SecurityUtils.getUsername());
        puStoreInDomHead.setIexchrate(1);
        puStoreInDomHead.setCexch_name("美元");
        puStoreInDomHead.setBpufirst("0");
        puStoreInDomHead.setCvencode("2202001");
        puStoreInDomHead.setCvouchtype("01");
        puStoreInDomHead.setCwhcode("01");
        puStoreInDomHead.setBrdflag(1);
        puStoreInDomHead.setCsource("普通采购");
        //创建表体信息
        List<Object> bodyList = new ArrayList<>();
        int i = 1;
        for (CcRukuInfo rukuInfo : list) {
            PuStoreInDomBody body = new PuStoreInDomBody();
            body.setCinvcode(rukuInfo.getItemId());
            body.setCinvm_unit(rukuInfo.getUnit());
            body.setIquantity(rukuInfo.getRukuNum().doubleValue());
            body.setEditprop("A");
            body.setIrowno(Integer.toString(i));
            body.setImatsettlestate(0);
            bodyList.add(body);
        }
        Map<String, String> StringMap = HttpClientUnit.webServiceXml(puStoreInDomHead, bodyList,wLogin.toString(), "http://192.168.3.249:10000/u8api.asmx/PuStoreInAdd");

        return StringMap;
    }

}
